﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;
using TableTopWidgets;

namespace TabletopWidgetTestApp
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            xBorderMenu.parent = this;

            RNTControl r= new RNTControl();
            Canvas c = new Canvas();

            BitmapImage bpImage = new BitmapImage();
            Image image = new Image();
            bpImage.BeginInit();
            bpImage.UriSource = new Uri(@"Images/" + "Jellyfish.jpg", UriKind.RelativeOrAbsolute);
            bpImage.DecodePixelWidth = 270;
            bpImage.EndInit();
            image.Source = bpImage;
            c.Children.Add(image);
            r.Content = c;
            r.Height = 280;
            r.Width = 320;
            gridMain.Children.Add(r);
        }

        private void mouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.Source == this)
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Dwell.Start(this, 1000, new TimerCallback(RevealZoomMenu));
                }
            }
        }

        private void mouseUp(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Released)
            {
                if (Dwell.HasDwellTimer(this))
                {
                    Dwell.Stop(this);
                }
            }
        }

        private void Window_SizeChanged(object sender, MouseButtonEventArgs e)
        {
            
        }
        

        private void RevealZoomMenu(Object state)
        {
            zoomMenu.Visibility = System.Windows.Visibility.Visible;
            zoomMenu.SetPosition(Mouse.GetPosition(this).X, Mouse.GetPosition(this).Y, ActualWidth, ActualHeight);
            Canvas.SetZIndex(zoomMenu, Int32.MaxValue);
        }

        private void LeftButtonHandler(object sender, RoutedEventArgs e)
        {
            MakeBorderMenu("Left");
        }

        private void RightButtonHandler(object sender, RoutedEventArgs e)
        {
            MakeBorderMenu("Right");
        }

        private void TopButtonHandler(object sender, RoutedEventArgs e)
        {
            MakeBorderMenu("Up");            
        }

        private void BottomButtonHandler(object sender, RoutedEventArgs e)
        {
            MakeBorderMenu("Down");
        }

        private void MakeBorderMenu(string orientation)
        {
            double xCoord = Mouse.GetPosition(this).X;
            double yCoord = Mouse.GetPosition(this).Y;

            xBorderMenu.Visibility = System.Windows.Visibility.Visible;
            xBorderMenu.SwitchOrientation(orientation);
            xBorderMenu.SetPosition(xCoord, yCoord, this.ActualWidth, this.ActualHeight);
        }

        public void addRNTWindow(double x, double y)
        {
            RNTWindow anotherWindow = new RNTWindow();
            gridMain.Children.Add(anotherWindow);
        }

        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {

        }
    }
}
